

package com.mt.repair.controller.repairManagement;

import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import com.mt.repair.dto.repairManagement.NoticeCatUserEditDto;
import com.mt.repair.entity.repairManagement.NoticeCatUser;
import com.mt.repair.service.repairManagement.NoticeCatUserService;
import com.mt.repair.service.repairManagement.NoticeService;
import com.mt.common.system.service.UserService;


@Api(tags = "维修评价")
@RestController
@RequestMapping("/api/repair/repairManagement/NoticeCatUser")
@CrossOrigin(allowCredentials = "true")
public class NoticeCatUserController {
    private static Logger logger = LoggerFactory.getLogger(NoticeCatUserController.class);


    @Autowired
    private NoticeCatUserService noticeCatUserService;
    @Autowired
    private NoticeService noticeService;
    @Autowired
    private UserService userService;

    /**
     * 根据分页参数查询维修评价集合
     *
     * @param pageDTO 分页条件
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:NoticeCatUser:view')")
    @ApiOperation("分页查询维修评价")
    @ApiPageParam
    @PostMapping("/findNoticeCatUsers")
    public PageResultDTO findNoticeCatUsers(@RequestBody PageDTO pageDTO) {
        return this.noticeCatUserService.findNoticeCatUsers(pageDTO);
    }

    /**
     * 根据ID查询指定的维修评价
     *
     * @param noticeCatUserId Id
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:NoticeCatUser:view')")
    @ApiOperation("根据id查询维修评价")
    @ApiPageParam
    @PostMapping("/findNoticeCatUser")
    public NoticeCatUser findNoticeCatUser(@RequestParam Long noticeCatUserId) {
        return this.noticeCatUserService.findNoticeCatUser(noticeCatUserId);
    }

    /**
     * 根据ID查询指定的维修评价(包含外键名称)
     *
     * @param noticeCatUserId Id
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:NoticeCatUser:view')")
    @ApiOperation("根据ID查询指定的维修评价(包含外键名称)")
    @PostMapping("/findNoticeCatUserForView")
    public NoticeCatUser findNoticeCatUserForView(@RequestParam Long noticeCatUserId) {
        return this.noticeCatUserService.findNoticeCatUserWithForeignName(noticeCatUserId);
    }

    /**
     * 根据ID查询指定的维修评价(包含维修评价和外键名称)
     *
     * @param noticeCatUserId Id
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:NoticeCatUser:view')")
    @ApiOperation("根据ID查询指定的维修评价(包含维修评价和外键名称)")
    @PostMapping("/findNoticeCatUserForEdit")
    public NoticeCatUserEditDto findNoticeCatUserForEdit(@RequestParam Long noticeCatUserId) {
        NoticeCatUserEditDto noticeCatUserEditDto = new NoticeCatUserEditDto();
        noticeCatUserEditDto.setNoticeCatUser(this.noticeCatUserService.findNoticeCatUserWithForeignName(noticeCatUserId));

        this.prepareNoticeCatUserEditDto(noticeCatUserEditDto);

        return noticeCatUserEditDto;
    }

    /**
     * 根据ID查询指定的维修评价(只提取ID 和 Name)
     *
     * @param noticeCatUserId Id
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:NoticeCatUser:view')")
    @ApiOperation("根据ID查询指定的维修评价(只提取ID 和 Name)")
    @PostMapping("/findNoticeCatUsersWithIdNameById")
    public NoticeCatUser findNoticeCatUsersWithIdNameById(@RequestParam Long noticeCatUserId) {
        return this.noticeCatUserService.findNoticeCatUsersWithIdNameById(noticeCatUserId);
    }

    /**
     * 根据名称查询维修评价集合(只提取ID 和 Name)
     *
     * @param noticeCatUserName 名称
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:NoticeCatUser:view')")
    @ApiOperation("根据名称查询维修评价集合(只提取ID 和 Name)")
    @PostMapping("/findNoticeCatUsersWithIdNameByName")
    public List<NoticeCatUser> findNoticeCatUsersWithIdNameByName(@RequestParam String noticeCatUserName) {
        return this.noticeCatUserService.findNoticeCatUsersWithIdNameByName(noticeCatUserName);
    }


    /**
     * 创建新的维修评价
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:NoticeCatUser:add')")
    @ApiOperation("创建新的维修评价")
    @PostMapping("/createNoticeCatUser")
    public NoticeCatUserEditDto createNoticeCatUser() {
        NoticeCatUserEditDto noticeCatUserEditDto = new NoticeCatUserEditDto();
        noticeCatUserEditDto.setNoticeCatUser(new NoticeCatUser());

        this.prepareNoticeCatUserEditDto(noticeCatUserEditDto);
        return noticeCatUserEditDto;
    }

    private void prepareNoticeCatUserEditDto(NoticeCatUserEditDto noticeCatUserEditDto) {
        //TODO: 以下代码可以注释掉，此行代码即时加载所有外键对象，以便选择。如果不在此加载，可以在界面上实现延迟加载。如果外键对象超过 500 行，建议采用延迟加载
        noticeCatUserEditDto.setNoticeNotices(this.noticeService.findAllNoticesWithIdName());
        //TODO: 以下代码可以注释掉，此行代码即时加载所有外键对象，以便选择。如果不在此加载，可以在界面上实现延迟加载。如果外键对象超过 500 行，建议采用延迟加载
        noticeCatUserEditDto.setUserUsers(this.userService.findAllUsersWithIdName());
    }

    /**
     * 新增保存维修评价
     *
     * @param noticeCatUser 实体对象
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:NoticeCatUser:add')")
    @ApiOperation("新增保存维修评价")
    @PostMapping("/saveNoticeCatUser")
    public NoticeCatUser saveNoticeCatUser(@RequestBody NoticeCatUser noticeCatUser) {
        return this.noticeCatUserService.saveNoticeCatUser(noticeCatUser);
    }

    /**
     * 修改保存维修评价
     *
     * @param noticeCatUser 实体对象
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:NoticeCatUser:update')")
    @ApiOperation("修改保存维修评价")
    @PostMapping("/updateNoticeCatUser")
    public NoticeCatUser updateNoticeCatUser(@RequestBody NoticeCatUser noticeCatUser) {
        return this.noticeCatUserService.updateNoticeCatUser(noticeCatUser);
    }

    /**
     * 根据ID删除维修评价
     *
     * @param noticeCatUserId ID
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:NoticeCatUser:remove')")
    @ApiOperation("根据ID删除维修评价")
    @PostMapping("/deleteNoticeCatUser")
    public void deleteNoticeCatUser(@RequestParam Long noticeCatUserId) {
        this.noticeCatUserService.deleteNoticeCatUser(noticeCatUserId);
    }


}

